package leetcode;

import java.util.Stack;

/**
 * TODO
 *
 * @author pengzhikang
 * @date 2022/10/9 16:27
 * @since 1.0.0
 */
public class MyStack1 {

    private Stack<Integer> stackData;
    private Stack<Integer> stackMin;

    public MyStack1() {
        this.stackData = new Stack<>();
        this.stackMin = new Stack<>();
    }


    public int push(int item) {
        if (stackMin.isEmpty() || item <= stackMin.pop()) {
            stackMin.push(item);
        }
        stackData.push(item);

        return item;
    }

    public int pop() {
        int value = stackData.pop();
        if(value == getMin()) {
            stackMin.pop();
        }
        return value;
    }

    public int getMin() {
        return stackMin.peek();
    }


}
